#include "test.h"

#include <thread>
#include <libgo/context/fiber/context.h>
#include <libgo/task/task.h>
#include <libgo/scheduler/processer.h>
#include <libgo/coroutine.h>

namespace samp16 {

    void foo() {
        printf("function pointer\n");
    }
}

SAMP_TEST(16) {
    using namespace samp16;

#define RUN 0

#if (RUN == 0)

    auto proc = co_sched.mainProcesser();

    co::FiberScopedGuard sg;

    co::Processer::GetCurrentProcesser() = proc;

    co::Task task(foo, 1 * 1024 * 1024);

    task.state_ = co::TaskState::runnable;
    task.proc_ = proc;

    task.SwapIn();
#endif

#if (RUN == 1)

    auto proc = co_sched.mainProcesser();

    co::Task task(foo, 1 * 1024 * 1024);
    co_sched.AddTask(&task);

    proc->Process();
#endif

#if (RUN == 2)

    using namespace samp16;

    go foo;

    co_sched.mainProcesser()->Process();
#endif

    SAMP_RTN(0);
}